// miniprogram/pages/home/home.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.onGetOpenid();
  },
  onGetOpenid: function() {
    let that = this;
    // 调用云函数
    wx.cloud.callFunction({
      name: 'login',
      data: {},
      success: res => {
        console.log('[云函数] [login] user openid: ', res.result.openid)
        let openid = res.result.openid;
        app.globalData.openid = res.result.openid;

       
      },
      fail: err => {
        console.error('[云函数] [login] 调用失败', err)
        wx.navigateTo({
          url: '../deployFunctions/deployFunctions',
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.onGetOpenid();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  goOne: function(){
    let url = '/pages/one/one';
    wx.navigateTo({
      url: url
    })
  },
  goTwo: function(){
    let url = '/pages/two/two';
    wx.navigateTo({
      url: url
    })
  },
  goThree: function(){
    let url = '/pages/examhome/examhome';
    wx.navigateTo({
      url: url
    })
  },
  goFour: function(){
    let url = '/pages/challenge/challenge';
    wx.navigateTo({
      url: url
    })
  },
  goFive: function(){
    let url = '/pages/five/five';
    wx.navigateTo({
      url: url
    })
  },
  goSix: function(){
    let url = '/pages/six/six';
    wx.navigateTo({
      url: url
    })
  },
  goHistory: function(){
    let url = '/pages/history/history';
    wx.navigateTo({
      url: url
    })
  },
  go: function(){
    wx.showToast({
      icon: 'none',
      title: '待定功能'
    })
  }         
})